#include "l_block.h"

l_block::l_block(int posy, int posx)
{
    //Initialize matrix (T-Position)
    for(int i=0; i<4; i++)
    {
        for(int j=0; j<4; j++)
        {
            if(((i==2) && ((j>=0)&&(j<=2))) || (i==1 && j==2))
                m_pos_matrix[i][j] = true;
            else
                m_pos_matrix[i][j] = false;
        }
    }

    //Initialize state, position and color
    m_state = S_UP;
    m_position[0] = posy;
    m_position[1] = posx-1;
    m_color = C_GREEN;
}

l_block::~l_block()
{
    //dtor
}

void l_block::m_Rotate()
{

    switch(m_state)
    {
        case S_DOWN:
        {
            m_state=S_LEFT; //Change block state

            //Just update necessary positions
            m_pos_matrix[2][0] = false;
            m_pos_matrix[2][2] = false;
            m_pos_matrix[3][0] = false;

            m_pos_matrix[1][1] = true;
            m_pos_matrix[1][0] = true;
            m_pos_matrix[3][1] = true;

            break;
        }

        case S_LEFT:
        {
            m_state=S_UP; //Change block state


            //Just update necessary positions
            m_pos_matrix[1][0] = false;
            m_pos_matrix[3][1] = false;
            m_pos_matrix[1][1] = false;

            m_pos_matrix[1][2] = true;
            m_pos_matrix[2][0] = true;
            m_pos_matrix[2][2] = true;

            break;
        }

        case S_UP:
        {
            m_state=S_RIGHT; //Change block state


            //Just update necessary positions
            m_pos_matrix[1][2] = false;
            m_pos_matrix[2][0] = false;
            m_pos_matrix[2][2] = false;

            m_pos_matrix[1][1] = true;
            m_pos_matrix[3][2] = true;
            m_pos_matrix[3][1] = true;

            break;
        }

        case S_RIGHT:
        {
            m_state=S_DOWN; //Change block state

            //Just update necessary positions
            m_pos_matrix[1][1] = false;
            m_pos_matrix[3][2] = false;
            m_pos_matrix[3][1] = false;

            m_pos_matrix[2][0] = true;
            m_pos_matrix[2][2] = true;
            m_pos_matrix[3][0] = true;

            break;
        }

    }
}
